<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>03-发送验证码</title>
    <style>
        button {
            width: 115px;
            height: 23px;
            font-size: 12px;
        }

        input {
            height: 22px;
        }
    </style>
    <script>
        window.onload = function () {
           let btn = document.getElementById("btn");
           btn.onclick = function () {
               btn.disabled = true;
               let num = 5;
               btn.innerHTML = num + "秒后重新获取"
               let timer = setInterval(function () {
                   num--;
                   btn.innerHTML = num + "秒后重新获取";

                   if(num === 0){
                       clearInterval(timer);
                       btn.disabled = false;
                       btn.innerHTML = "发送验证码";
                   }

               },1000);
           }

        }
    </script>
</head>
<body>
    <input type="text">
    <button id="btn">发送验证码</button>
</body>
</html>